<script>

import * as echarts from 'echarts';
// import $ from 'jquery'
export default {
  name: 'VisualizationTwelve',
  data() {
    return{

    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$axios.get('/api/vis/data20', {}).then(res => {
        if (res.data.code === 20041) {
          let data1 = [];
          let data2 = [];
          let data3 = [];
          for (let i = 0; i < res.data.data.length; i++) {
            if(res.data.data[i].param1 !== "其它") {
              data1.push(
                  res.data.data[i].param1
              );
              data2.push(
                  res.data.data[i].param2
              );
            }
          }
          //
          this.$axios.get('/api/vis/data21', {}).then(res => {
            if (res.data.code === 20041) {
              for (let i = 0; i < res.data.data.length; i++) {
                if(res.data.data[i].param1 !== "其它") {
                  data3.push(
                      res.data.data[i].param2
                  );
                }
              }
              this.init(data1, data2, data3)
            }
          }).catch(error => {
            this.open4(error);
          })
        }
      }).catch(error => {
        this.open4(error);
      })
    },
    open4(msg) {
      this.$notify.error({
        title: msg,
        message: '这是一条错误的提示消息'
      });
    },
    init(data1, data2, data3) {

      var chartDom = document.getElementById('main12');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        title: [
          {
            text: '房型的高评分与低评分'
          }
        ],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            crossStyle: {
              color: '#999'
            }
          }
        },
        toolbox: {
          feature: {
            dataView: { show: true, readOnly: false },
            magicType: { show: true, type: ['line', 'bar'] },
            restore: { show: true },
            saveAsImage: { show: true }
          }
        },
        legend: {
          data: ['高评分', '低评分']
        },
        xAxis: [
          {
            name: '房型',
            type: 'category',
            data: data1,
            axisPointer: {
              type: 'shadow'
            }
          }
        ],
        yAxis: [
          {
            type: 'value',
            name: '好评数量',
            min: 0,
            max: 250,
            interval: 50,
            axisLabel: {
              formatter: '{value}'
            }
          }
        ],
        series: [
          {
            name: '高评分',
            type: 'bar',
            tooltip: {
              valueFormatter: function (value) {
                return value;
              }
            },
            data: data2
          },
          {
            name: '低评分',
            type: 'bar',
            tooltip: {
              valueFormatter: function (value) {
                return value;
              }
            },
            data: data3
          }
        ]
      };

      option && myChart.setOption(option);
    }
  }

}
</script>

<template>
  <div id="main12"></div>
</template>

<style scoped>
#main12 {
  width: 100%;
  height: 100%;
}
</style>